<?php

class EditedReportParameter extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'edited_report_parameter':
	 * @var integer $id
	 * @var string $name
	 * @var string $label
	 * @var string $type
	 * @var string $value
	 * @var string $type_list
	 * @var integer $edited_report_id
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return EditedReportParameter the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'edited_report_parameter';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, label, type, value, edited_report_id', 'required'),
			array('edited_report_id', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>100),
			array('label', 'length', 'max'=>255),
			array('type', 'length', 'max'=>8),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, label, type, value, edited_report_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'report' => array(self::BELONGS_TO, 'Report', 'edited_report_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'name' => 'Name',
			'label' => 'Label',
			'type' => 'Type',
			'value' => 'Value',
			'type_list' => 'List',
			'edited_report_id' => 'Edited Report',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('name',$this->name,true);

		$criteria->compare('label',$this->label,true);

		$criteria->compare('type',$this->type,true);

		$criteria->compare('type_list',$this->type_list,true);

		$criteria->compare('value',$this->value,true);

		$criteria->compare('edited_report_id',$this->edited_report_id);

		return new CActiveDataProvider('EditedReportParameter', array(
			'criteria'=>$criteria,
		));
	}
	
	public function getValues() {
		if (isset($this->type_list) && trim($this->type_list) != '') {
			return split("(\r|\n|\r\n)", $this->type_list);
		} else {
			return array();
		}
	}
	
	public function getAttributes() {
		$attr = parent::getAttributes();
		$attr['values'] = $this->getValues();
		return $attr;
	}
}